<template>
	<view class="container">
		<view v-if="checkPermi(['puyu:memberintegral:add'])">
			<button class="uni-button" style="color:#ffffff;backgroundColor:#993399;borderColor:#993399;width: 100%;margin: 10rpx 0;"
				type="primary" @click="handleAddMemberIntegral()">添加队员积分</button>
		</view>
		<uni-section title="搜索" type="line" v-if="checkPermi(['puyu:memberintegral:add'])">
			<view class="query-form">
				<view class="query-item">
					<uni-easyinput v-model="queryParams.memberName" placeholder="请输入队员姓名" />
				</view>
				<view class="query-item">
					<uni-easyinput v-model="queryParams.phone" placeholder="请输入手机号" />
				</view>
				<view class="query-item">
					<uni-data-select v-model="queryParams.delFlag" :localdata="delFlagRange" placeholder="请选择删除标识"></uni-data-select>
				</view>
				<view class="query-item">
					<button class="uni-button" size="mini" type="primary" @click="handleQuery">搜索</button>
				</view>
			</view>
		</uni-section>
		<uni-section :title="'队员积分:共 ' + total + ' 条'" type="line"></uni-section>
		<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
			<uni-tr>
				<uni-th align="center">队员积分数据</uni-th>
				<uni-th width="250rpx" align="center">操作</uni-th>
			</uni-tr>
			<uni-tr v-for="(item, index) in memberIntegralList" :key="index">
				<uni-td>
					<view class="name">队员ID: {{ item.memberId }}</view>
					<view class="name">队员姓名: {{ item.memberName }}</view>
					<view class="name">手机号: {{ item.phone }}</view>
					<view class="name">基础积分: {{ item.integralBasic }}</view>
					<view class="name">最后一次积分: {{ item.integralLast }}</view>
					<view class="name">积分明细计算: {{ item.integralCalculate }}</view>
					<view class="name">积分合计: {{ item.integralTotal }}</view>
					<view class="name">删除标识: {{ getDelFlag(item.delFlag) }}</view>
					<view class="name remark">{{ item.remark }}</view>
				</uni-td>
				<uni-td align="center">
					<view v-if="checkPermi(['puyu:memberintegral:edit'])">
						<button class="uni-button" size="mini" type="primary"
							@click="handleEditMemberIntegral(item)">修改</button>
					</view>
					<view v-if="checkPermi(['puyu:memberintegral:query'])">
						<button class="uni-button" size="mini" type="default"  @click="handlMemberIntegral(item)"
							style="color:#ffffff;backgroundColor:#bebe00;borderColor:#bebe00 width: 100%;">积分详情</button>
					</view>
					<view v-if="checkPermi(['puyu:memberintegral:remove'])">
						<button class="uni-button" size="mini" type="warn"
							@click="handleDeleteMemberIntegral(item)">删除</button>
					</view>
				</uni-td>
			</uni-tr>
		</uni-table>
		<uni-pagination :page-size="queryParams.pageSize" :current="queryParams.pageNum" :total="total" @change="change"
			prev-text="前一页" next-text="后一页" />
		<view class="page-sum">
			<text>当前页：{{ queryParams.pageNum }}，数据总量：{{ total }} 条，每页数据：{{ queryParams.pageSize }} 条</text>
		</view>
	</view>
</template>

<script>
	import {
		checkPermi,
		checkRole
	} from "@/utils/permission";
	import { getDicts } from "@/api/system/dict/data";
	import { listMemberintegral, delMemberintegral } from "@/api/puyu/memberintegral";
	import { parseTime } from '@/utils/common';
	export default {
		data() {
			return {
				// 遮罩层
				loading: true,
				// 总条数
				total: 0,
				// 队员积分数据
				memberIntegralList: null,
				delFlagRange: [
					{ value: "0", text: "存在" },
					{ value: "2", text: "删除" },
				],
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 5,
					delFlag: null,
					memberName: null,
					phone: null,
				},
			}
		},
		onShow() {
			this.getList();
		},
		methods: {
			checkPermi,
			checkRole,
			parseTime,
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 查询课时点名列表 */
			getList() {
				this.loading = true;
				this.queryParams.orderByColumn = 'integralTotal'; //查询字段是表格中字段名字
				this.queryParams.isAsc = 'descending'; //动态取值排序顺序
				listMemberintegral(this.queryParams).then(response => {
					this.memberIntegralList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 根据delFlag获取删除标识
			getDelFlag(delFlag) {
				let obj = this.delFlagRange.filter(item => item.value == delFlag)[0]
				return obj?obj.text:'';
			},
			/** 添加队员积分 */
			handleAddMemberIntegral() {
				this.$tab.navigateTo('/pages/puyu/member-integral/add-member-integral');
			},
			/** 修改体能测试 */
			handleEditMemberIntegral(item) {
				this.$tab.navigateTo('/pages/puyu/member-integral/edit-member-integral?item=' + encodeURIComponent(JSON.stringify(item)));
			},
			/** 删除体能测试 */
			handleDeleteMemberIntegral(item) {
				const memberIds = item.memberId;
				this.$modal.confirm('是否确认删除体能测试ID为"' + memberIds + '"的数据项？').then(function() {
				  return delMemberintegral(memberIds);
				}).then(() => {
				  this.getList();
				  this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			// 分页触发
			change(e) {
				this.$refs.table.clearSelection()
				this.getData(e.current)
			},
			// 获取数据
			getData(pageCurrent, value = '') {
				this.queryParams.pageNum = pageCurrent
				this.getList()
			},
			/** 积分详情 */
			handlMemberIntegral(item) {
				this.$tab.navigateTo('/pages/puyu/member-integral/member-integral?memberId=' + item.memberId);
			},
		}
	}
</script>

<style lang="scss" scoped>
	/* #ifndef H5 */
	/* page {
	padding-top: 85px;
} */
	/* #endif */

	.page-sum {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.query-form {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		background-color: #ffffff;
		margin-bottom: 10px;
	}

	.query-item {
		margin: 5rpx;
		padding: 5rpx;
	}
	
	.query-item-value {
		margin-top: 5rpx;
		color: darkgray;
	}
	.remark {
		color: #993399;
		font-weight: bolder;
	}
</style>